<template>
	<view class="wf-box" :style="{ paddingTop: totalheight }">
		<view class="head" :style="{ paddingTop: topheight }">
			<view class="head-np">
				<view class="back" @click="back">
					<image src="../../static/img/chat-09.png"></image>
				</view>
				<view class="title">群聊名称</view>
				<view></view>
			</view>
		</view>
		
		<view class="main">
			<view class="set-box">
				<view class="set-tip">修改群聊名称后，将在群里通知其他成员。</view>
				
				<view class="set-warp">
					<!-- 请输入群聊名称 -->
					<input type="text" placeholder="请输入群聊名称" v-model="group.name" />
				</view>
			</view>
		</view>
		
		<view class="footer-warp">
			<view @click="submit">保存</view>
		</view>
	</view>
</template>

<script>
	import navBarMixin from '@/mixin/navBarMixin.js'
	export default {
		data() {
			return {
				groupId: '',
				group: '', // 群信息
				placeholder: ''
			}
		},
		mixins: [navBarMixin],
		methods: {
			back() {
				uni.navigateBack()
			},
			
			loadGroupInfo(id) {
				this.$http({
					url: `/group/find/${id}`,
					method: 'GET'
				}).then((group) => {
					this.group = group;
					// 更新聊天页面的群聊信息
					this.$store.commit("updateChatFromGroup", group);
					// 更新聊天列表的群聊信息
					this.$store.commit("updateGroup", group);
			
				});
			},
			
			submit() {
				this.$http({
					url: "/group/modify",
					method: "PUT",
					data: this.group
				}).then((group) => {
					this.$store.commit("updateGroup", group);
					uni.showToast({
						title: "修改群名成功",
						icon: 'none'
					});
					
					setTimeout(() => {
						let pages = getCurrentPages();
						let prevPage = pages[pages.length - 2];
						prevPage.$vm.loadGroupInfo();
						uni.navigateBack();
					}, 2000);
				})
			}
		},
		onLoad(options) {
			const systemInfo = uni.getSystemInfoSync()
			const height = systemInfo.statusBarHeight;
			const navigationBarHeight = systemInfo.platform === 'android' ? 48 : 48 // 根据不同平台设置导航栏高度 
			const totalHeight = height + navigationBarHeight
			this.topheight = height + 'px';
			this.totalheight = totalHeight + 'px'
			
			this.groupId = options.groupId
			this.loadGroupInfo(options.id);
			// this.placeholder = this.$t('__1__')
		}
	}
</script>

<style lang="scss" scoped>
	.wf-box {
		position: relative;
		overflow: hidden;
		
		.head {
			position: fixed;
			top: 0;
			z-index: 1;
			width: 100%;
			background: #fff;
			
			.head-np {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				height: 96rpx;
				padding: 0 30rpx;
				box-sizing: border-box;
			}
			
			.back {
				color: #333;
				font-size: 28rpx;
				image {
					width: 20rpx;
					height: 37rpx;
				}
			}
			
			.title {
				font-size: 36rpx;
				font-weight: bold;
			}
		}
	
		.main {
			margin-top: 30rpx;
			padding: 0 30rpx;
			.set-box {
				padding: 30rpx;
				min-height: 820rpx;
				box-sizing: border-box;
				background: #fff;
				border-radius: 6rpx;
				.set-tip {
					text-align: center;
					font-size: 28rpx;
					color: #333;
				}
				.set-warp {
					padding: 0 30rpx;
					margin-top: 50rpx;
					height: 80rpx;
					border-radius: 6rpx;
					background: #F8F8F8;
					input {
						height: 100%;
						font-size: 24rpx;
					}
					
				}
			}
		}
		.footer-warp {
			padding: 0 100rpx;
			margin-top: 100rpx;
			view {
				line-height: 80rpx;
				text-align: center;
				border-radius: 50rpx;
				background-color: $theme-color-a;
				color: #fff;
				font-size: 32rpx;
			}
		}
	}
</style>